package com.guinea.generator;

import com.guinea.core.utils.StringUtils;

public class MappingProperty {
	String name;

	String type;

	String show;
	
	String search;
	
	String dict;

	String column;

	String length;

	String precision;

	String scale;

	String defaultValue;

	String notNull;

	String unique;

	MappingFormElement element;

	MappingClass parent;

	public MappingProperty(String name, String type, String show, String search, String dict,
			String column, String length, String precision, String scale,
			String defaultValue, String notNull, String unique) {
		super();
		this.name = name;
		this.type = StringUtils.capitalize(StringUtils.defaultString(type,
				ConfigUtils.TYPE_STRING).toLowerCase());
		this.show = StringUtils.defaultString(show, "false");
		this.search = StringUtils.defaultString(search, "false");
		this.dict = dict;
		this.column = StringUtils.defaultString(column,
				ConfigUtils.camelToTable(name)).toUpperCase();
		this.length = this.type.equals(ConfigUtils.TYPE_STRING) ? StringUtils
				.defaultString(length, "255") : length;
		this.precision = this.type.equals(ConfigUtils.TYPE_DOUBLE) ? StringUtils
				.defaultString(precision, "23")
				: precision;
		this.scale = scale;
		this.defaultValue = defaultValue;
		this.notNull = StringUtils.defaultString(notNull, "false");
		this.unique = StringUtils.defaultString(unique, "false");
	}

	public String getSql() {
		String sql = "";
		sql += ConfigUtils.camelToTable(name);
		if (type.equalsIgnoreCase("string")) {
			sql += " varchar";
		}
		return sql;
	}
	
	public boolean isDictGroup(){
		return (this.dict != null && this.dict.indexOf(":") > -1)? true:false;
	}
	
	public String getDictGroupType(){
		String result = null;
		if(this.dict != null && this.dict.indexOf(":") > -1){
			String[] s = StringUtils.split(this.dict,":");
			if(s.length > 0)
			result = s[0];
		}
		return result;
	}
	
	public String getDictGroupGroup(){
		String result = null;
		if(this.dict != null && this.dict.indexOf(":") > -1){
			String[] s = StringUtils.split(this.dict,":");
			if(s.length > 1)
			result = s[1];
		}
		return result;
	}
	
	public String getDictGroupSerial(){
		String result = null;
		if(this.dict != null && this.dict.indexOf(":") > -1){
			String[] s = StringUtils.split(this.dict,":");
			if(s.length > 2)
			result = s[2];
		}
		return result;
	}

	public String getColumn() {
		return column;
	}

	public void setColumn(String column) {
		this.column = column;
	}

	public String getDefaultValue() {
		return defaultValue;
	}

	public void setDefaultValue(String defaultValue) {
		this.defaultValue = defaultValue;
	}

	public MappingFormElement getElement() {
		return element;
	}

	public void setElement(MappingFormElement element) {
		this.element = element;
	}

	public String getNotNull() {
		return notNull;
	}

	public void setNotNull(String isNotNull) {
		this.notNull = isNotNull;
	}

	public String getUnique() {
		return unique;
	}

	public void setUnique(String isUnique) {
		this.unique = isUnique;
	}

	public String getLength() {
		return length;
	}

	public void setLength(String length) {
		this.length = length;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPrecision() {
		return precision;
	}

	public void setPrecision(String precision) {
		this.precision = precision;
	}

	public String getScale() {
		return scale;
	}

	public void setScale(String scale) {
		this.scale = scale;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public MappingClass getParent() {
		return parent;
	}

	public void setParent(MappingClass parent) {
		this.parent = parent;
	}

	public String getShow() {
		return show;
	}

	public void setShow(String show) {
		this.show = show;
	}

	public String getDict() {
		return dict;
	}

	public void setDict(String dict) {
		this.dict = dict;
	}

	public String getSearch() {
		return search;
	}

	public void setSearch(String search) {
		this.search = search;
	}

}
